Department of Methodology and Statistics, Utrecht University
2025-10-20
Intro
Open Street Maps (OSM) can be a great data source
In this presentation, we will see how to extract and use this data to map castles in France using R
For extracting, we will use the package ‘osmextract’
The function ‘oe_get()’ downloads a mirror of the OSM data base as specified by the user
Then, queries are performed locally using SQL
We use ‘tidyverse’ and ‘sf’ for operational procedures such as (spatial) data wrangling etc
Downloading the data
# load packageslibrary(tidyverse)library(sf)library(osmextract)# wait 1000 seconds for the internet operation to completeoptions(timeout =1000)# retrieve a data extract from a providercastles <-oe_get(# define a geographical area to be matched with a .osm.pbf fileplace ="France",# define a providerprovider ="geofabrik",# query the database locally (!) from a downloaded odm extract# only layer is filtered before downloading the extractquery =" SELECT * FROM multipolygons WHERE historic = 'castle' ",# specify additional columns corresponding to OSM tagsextra_tags =c("castle_type"),# define directory for the osm extract download_directory =getwd(),# no messagesquiet =TRUE)